/*用于判断输入的格式是否正确*/
var isUsername = false;
var isPassword = false;
var isPw2 = false;
var iszpd = false;
/*输入手机号码*/
var mobile = document.querySelector('#mobile');
mobile.onchange = function(){
	var sj = document.querySelector(".mobile-tips")
	if(/^1[34578]\d{9}$/.test(this.value)){
		
		sj.innerHTML = 'ok';
		sj.style.color = 'green'
		isUsername = true;
		console.log(isUsername)
	}else{
		sj.innerHTML = '（手机输入格式错误）'
		sj.style.color = 'red';
		isUsername=false;
	}
}
/*输入密码*/
var pwd = document.getElementById("captcha")
pwd.onchange = function(){
	var mm1 = document.querySelector('.captcha-tips');
	if(/^\w{6,12}$/.test(this.value)){
		mm1.innerHTML = 'ok';
		mm1.style.color = 'green';
		isPassword = true;
	}else{
		mm1.innerHTML = '密码错误';
		mm1.style.color = 'red';
		isPassword=false;
	}
}
/*确认密码*/
var pwd2 = document.getElementById("code");
var qrmm = document.querySelector('.code-tips');
pwd2.onblur = function(){
	if (this.value==pwd.value) {
		qrmm.innerHTML = 'ok';
		qrmm.style.color = 'green';
		isPw2=true;
	} else{
		qrmm.innerHTML = '密码不正确';
		qrmm.style.color = 'red';
		isPw2=false;
	}
}
/*总判断*/
window.onclick = function(){
	if(pwd.value==pwd2.value){
		if(isPassword){
			qrmm.innerHTML = 'ok';
			qrmm.style.color = 'green';
			isPw2=true;
			iszpd=true;
			console.log('总判断:'+iszpd)
		}
		
	}else{
		if(pwd2.value){
			qrmm.innerHTML = '密码不正确';
		qrmm.style.color = 'red';
		isPw2=false;
		}
		
		iszpd=false;
		console.log('总判断:'+iszpd)
	}
}
/*提交*/
var btn = document.querySelector('.btn2');
btn.onclick = function(){
	if(isUsername&&isUsername&&isPw2&&iszpd){
	console.log(1)
	let url=`http://jx.xuzhixiang.top/ap/api/reg.php?username=${mobile.value}&password=${pwd.value}`;
	$.ajax({
		type:"get",
		url:url,
		async:true,
		success:function(res){
			console.log(res)
			var obj = JSON.parse(res)
			alert(obj.msg)
			location.href = '../html/login.html'
		}
	});
	}else{
		console.log(2)
	}
}
var username = document.getElementById("username");
var password = document.getElementById("password");
var dlbtn = document.querySelector('.btn1');
dlbtn.onclick = function(){
	console.log('我是登录');
	url1 = `http://jx.xuzhixiang.top/ap/api/login.php?username=${username.value}&password=${password.value}`;
	$.ajax({
		type:"get",
		url:url1,
		async:true,
		success:function(res){
			var obj = JSON.parse(res);
			console.log(obj);
			if(obj.code){
				location.href='../html/index.html'
				Cookie.setCookie('yhid',obj.data.id,7)
			}else{
				alert(obj.msg)
			}
		}
	});
}
